/**
 * 
 */
package common;

import java.io.Serializable;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.LinkedList;
import java.util.List;

import bedside.Alarm;
import bedside.CallButton;
import bedside.VitalSign;
import bedside.VitalSignBuffer;

/**
 * Remote interface for the bedside monitors.
 * 
 * @author Eric Lutley
 */
public class BedsideMonitor implements AlarmReceiver, Serializable{
	
	
	//Class Constants
	
	//Class Variables
	List<VitalSign> myVitals = null;
	CentralInterface crr = null;
	CallButton cb = null;
	VitalSignBuffer myBuffer = new VitalSignBuffer();
	
	/**
	 * 
	 */
	public BedsideMonitor(){
		
		  /**/     	System.setSecurityManager(new RMISecurityManager());
		  /**/     	Registry registry;
		try {
			registry = LocateRegistry.getRegistry();
			crr = (CentralInterface)registry.lookup("Central Station");
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  /**/ catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}       
		
		
		//Create a List of Vitals
		myVitals = new LinkedList<VitalSign>();
		
		//Create Heart Setup
		VitalSign vs = new VitalSign(10, 25, 50, 60,
				 1000, VitalSign.HEART);
		vs.register(this);
		vs.register(crr);
		vs.setVitalSignBuffer(myBuffer);
		myVitals.add(vs);
		
		//Create Lung
		vs = new VitalSign(3, 15, 85, 97,
				 10000, VitalSign.LUNGS);
		vs.register(this);
		vs.register(crr);
		vs.setVitalSignBuffer(myBuffer);
		myVitals.add(vs);
		
		//Create BP
		vs = new VitalSign(3, 15, 85, 97,
				 10000, VitalSign.BP);
		vs.register(this);
		vs.register(crr);
		vs.setVitalSignBuffer(myBuffer);
		myVitals.add(vs);
		
		//Create Blood Ox
		vs = new VitalSign(91, 93, 100, 100,
				 1000, VitalSign.OX);
		vs.register(this);
		vs.setVitalSignBuffer(myBuffer);
		vs.register(crr);
		myVitals.add(vs);
		
		cb = new CallButton(crr);
	}
	
	public void registerVitalListener( VitalSignListener vsl ){
		myBuffer.addVitalSignListener(vsl);
	}
	
	public List<VitalSign> getVitals(){
		return myVitals;
	}
	
	public void alarmTriggered( Alarm alarm ) throws RemoteException{
		
	}
	
	public void alarmReset( Alarm alarm ) throws RemoteException{
	
	}
	
	
	
}
